/**
 * Created by chenshengli on 2015/7/2 0002.
 */

var mongoTemplate = require('../mongoTemplate');
var Constants = require('../constants');

exports.groupHosts = function (hosts,envs) {
    var env = {};
    for(var index in envs){
        var _id = envs[index]._id.toString();
        env[_id] = envs[index];
    }
    var exchange = {};
    for (var i = 0; i < hosts.length; i++) {
        var host = hosts[i];
        host.hostEnv = env[host.hostEnv];
        if(!host.hostParent){
            exchange[host._id] = host;
        }
    }
    var result = [];
    for(var key in exchange){
        result[result.length] = exchange[key];
    }
    return result;
}